package com.dondedesigns.eh.controller.bullets;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

import com.dondedesigns.eh.persistence.BlUser;
import com.dondedesigns.eh.persistence.Bullet;
import com.dondedesigns.eh.persistence.dao.BlUserDAO;
import com.opensymphony.xwork2.ActionSupport;

public class MembersBullets extends ActionSupport {

	private BlUserDAO blUserDAO;
	private List<BlUser> blUsersList;
	
	@Override
	public String execute() throws Exception {
		blUsersList = blUserDAO.selectAlive();
		return SUCCESS;
	}
	
	public List<BlUser> getBlUsersList() {
		return blUsersList;
	}
	
	public Map<String, Bullet> getBulletsList () {
		Map<String, Bullet> bulletMap = new HashMap<String, Bullet> ();
		for (BlUser blUser : blUsersList) {
			TreeSet<Bullet> orderedBullets = new TreeSet<Bullet>(blUser.getBullets());
			if (!orderedBullets.isEmpty()) {
				bulletMap.put(blUser.getUsername(), orderedBullets.first());
			}
		}
		return bulletMap;
	}

	public void setBlUserDAO(BlUserDAO blUserDAO) {
		this.blUserDAO = blUserDAO;
	}
	
	
	
}
